package com.cn.xiaonuo.tcrfinance.sysmgmt.controller;


import com.cn.xiaonuo.common.entity.SysLog;
import com.cn.xiaonuo.common.validated.util.ValidatorUtils;
import com.cn.xiaonuo.core.annotion.BusinessLog;
import com.cn.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import com.cn.xiaonuo.core.pojo.response.ResponseData;
import com.cn.xiaonuo.core.pojo.response.SuccessResponseData;
import com.cn.xiaonuo.tcrfinance.sysmgmt.param.SysConfigHpcParam;
import com.cn.xiaonuo.tcrfinance.sysmgmt.service.SysConfigHpcService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统配置信息
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
public class SysConfigHpcController  {
	@Autowired
	private SysConfigHpcService sysConfigService;

	/**
	 * 所有配置列表
	 */
	@PostMapping("/api/sys/config/list")
	@ApiOperation(value = "配置列表", notes = "配置列表")
	public ResponseData list(SysConfigHpcParam sysConfigParam){
		return new SuccessResponseData(sysConfigService.queryPage(sysConfigParam));
	}


	/**
	 * 配置信息
	 */
	@PostMapping("/api/sys/config/info")
	@ApiOperation(value = "配置信息", notes = "配置信息")
	public ResponseData info(@RequestBody SysConfigHpcParam sysConfigParam){
		return new SuccessResponseData(sysConfigService.getById(sysConfigParam.getId()));
	}

	/**
	 * 保存配置
	 */
	@SysLog("保存配置")
	@BusinessLog(title = "保存配置", opType = LogAnnotionOpTypeEnum.DETAIL)
	@PostMapping("/api/sys/config/save")
	@ApiOperation(value = "保存配置", notes = "保存配置")
	public ResponseData save(@RequestBody SysConfigHpcParam sysConfigParam){
		ValidatorUtils.validateEntity(sysConfigParam);
		sysConfigService.saveConfig(sysConfigParam);

		return new SuccessResponseData();
	}

	/**
	 * 修改配置
	 */
	@SysLog("修改配置")
	@BusinessLog(title = "修改配置", opType = LogAnnotionOpTypeEnum.DETAIL)
	@PostMapping("/api/sys/config/update")
	@ApiOperation(value = "修改配置", notes = "修改配置")
	public ResponseData update(@RequestBody SysConfigHpcParam sysConfigParam){
		ValidatorUtils.validateEntity(sysConfigParam);

		sysConfigService.update(sysConfigParam);

		return new SuccessResponseData();
	}

	/**
	 * 删除配置
	 */
	@SysLog("删除配置")
	@BusinessLog(title = "删除配置", opType = LogAnnotionOpTypeEnum.DETAIL)
	@PostMapping("/api/sys/config/delete")
	@ApiOperation(value = "删除配置", notes = "删除配置")
	public ResponseData delete(@RequestBody SysConfigHpcParam sysConfigHpcParam){
		sysConfigService.deleteBatch(sysConfigHpcParam.getIds());
		return new SuccessResponseData();
	}

}
